1 using UnityEngine;
2 using
System.Collections;
3
4 public
class BallLauncher : MonoBehaviour {
5
6     
public GameObject ballPreFab;
7     
public float ballSpeed = 5.0f;
8
9     
// Use this for initialization
10     
void Start () {
11     
12     }
13     
14     
// Update is called once per frame
15     
void Update () {
16         
if (Input.GetButtonDown("Fire1"))
17         {
18             GameObject instance = Instantiate(ballPreFab);
19             instance.transform.position = transform.position;
20             Rigidbody rb = instance.GetComponent<Rigidbody>();
21             Camera camera = GetComponentInChildren<Camera>();
22             rb.velocity = camera.transform.rotation * Vector3.forward * ballSpeed;
23         }
24     }
25 }


Gõ tìm kiếm nhanh...